import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int[] a=new int[n];
        Stack<Integer> s1=new Stack<>();
        Stack<Integer> s2=new Stack<>();
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
        }
        int max=0;
        s1.push(a[0]);
        for(int i=1;i<n;i++){
            int j=i;
            int count=0;
            while(a[j]<s1.peek()){
                s1.push(a[j]);
                j++;
            }
            while(s2.isEmpty()||a[j]>s2.peek()){
                s2.push(a[j]);
                j++;
            }
            count=s1.size();
            max=Math.max(count,max);
            while(!s2.isEmpty()&&s2.peek()>a[j]){
                s1.push(s2.pop());
            }
            s1.push(a[j]);
            i=j;
        }
        System.out.println(max);
    }
}